<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Group_Model extends CI_Model{
    function __construct()
    {
        parent::__construct();
    }
    function getAllData($num,$offset){
        $query = $this->db->get('group',$num,$offset);
      
        return $query->result();  
    } 
     function get_object($id)
    {
        $query = $this->db->get_where('group', array('group_id' =>$id));
        return $query->row();
    }
    function getNumData(){
        $query = $this->db->get('group');
        return $query->num_rows();
    }
   function optionCategory($value=0){
       $query = $this->db->get('group');
       $category_arr = $query->result();
       $str_opt = "";
       $str_opt = "<option value=''> Nhóm quảng cáo</option>";
       foreach($category_arr as $item_opt){
            $str_opt .="<option value='".$item_opt->group_id."'".(($value==$item_opt->group_id)?" selected":"")."> ".$item_opt->name."</option>";
        }
        return $str_opt;
   }
   function saveData($group_id,$data){
             if($group_id!=0){
                    $this->db->where('group_id',$group_id);
                    if($this->db->update('group',$data)){
                         return true;
                    }else{
                         return false;
                    }
             }else{
                    if($this->db->insert('group',$data)){
                        return true;
                        
                    }else{
                        return false;
                    }
            }
    }
    function get_num_data($group_id=0){
            $this->db->where('bl_active <>',-1);
             $query = $this->db->get('group');
             return $query->num_rows();
    }
    function get_all_data($group_id=0,$num,$offset)
    {
            $this->db->where('bl_active <>',-1);
            $query = $this->db->get('group',$num,$offset);
            return $query->result();
    }
    
    
  }
?>
